
#include <REGX51.H>
#include <INTRINS.H>

sbit _KEY_0 = P1^0;

unsigned char _num = 0;
unsigned char _flag = 0;

// 共阴 0-9
unsigned char _seg_data[] = {
	0x3F,
	0x06,
	0x5B,
	0x4F,
	0x66,
	0x6D,
	0x7D,
	0x07,
	0x7F,
	0x6F,
};

/**
 * 
 */
void seg()
{
	P2 = _seg_data[_num];

	if (9 < _num)
	{
		_num = 0;
	}
}

/**
 * 
 */
void clickBtn()
{
	if (0 == _KEY_0 && 0 == _flag)
	{
		_flag = 1;
	}

	if (1 == _KEY_0 && 1 == _flag)
	{
		_num++;
		_flag = 0;
	}
}

/**
 * 
 */
void main()
{	
	while(1)
	{
		clickBtn();
		seg();
	}
}
